package com.kuang.controller;

import com.kuang.dao.UserDao;
import com.kuang.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class UserController {

    @Autowired
    private UserDao userDao;

    @GetMapping("/userList")
    public List<User> getUserList() {
        List<User> userList = userDao.getUserList();
        return userList;
    }

    @GetMapping("/getUser/{id}")
    public User getUserById(@PathVariable("id") Integer id) {
        User user = userDao.getUserById(id);
        return user;
    }

    @GetMapping("/addUser")
    public String addUser() {
        User user = new User(7, "qqqwww", "qweqwq");
        userDao.addUser(user);
        return "新增成功!!!";
    }

    @GetMapping("/updUser")
    public String updUser(){
        User user = new User(7, "qqqwww", "123456");
        userDao.updUser(user);
        return "修改成功!!!";
    }

    @GetMapping("/delUser/{id}")
    public String delUser(@PathVariable("id")Integer id){
        userDao.delUser(id);
        return "删除成功!!!";
    }
}
